package com.xugongzhang.thread;

import lombok.Data;

import java.util.HashMap;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author X
 * @date 2022/11/26 23:28
 */
public class ManageServerConnectClientThread {
    
    private static HashMap<String, ServerConnectClientThread> map = new HashMap<>();
    
    public static void addServerConnectClientThread(String username, ServerConnectClientThread thread) {
        map.put(username, thread);
    }
    
    public static ServerConnectClientThread getServerConnectClientThread(String username) {
        return map.get(username);
    }
    
    public static void removeThread(String username) {
        map.remove(username);
    }
    
    // 返回在线用户列表，格式：“张三 李四 王五”
    public static String getOnlineUser() {
        // 遍历map的key就行了
        /*Set<String> strings = map.keySet();
        return strings.stream().collect(Collectors.joining(""));*/
        return String.join(" ", map.keySet());
    }

    public static HashMap<String, ServerConnectClientThread> getMap() {
        return map;
    }
}
